﻿package mortal.game.view.tianDiRank.panel
{
    import Message.Public.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.data.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.view.common.*;
    import mortal.game.view.tianDiRank.data.*;
    import mortal.game.view.tianDiRank.item.*;
    import mortal.mvc.core.*;

    public class TianDiEnterPanel extends BaseWindow
    {
        protected var _killDes:GTextFiled;
        protected var _tip:GTextFiled;
        protected var _posDes:GTextFiled;
        protected var _posTxt:GTextFiled;
        protected var _killTimesDes:GTextFiled;
        protected var _killTimesTxt:GTextFiled;
        protected var _attrList:CellsGridSprite;
        protected var _killPlayerName:GTextFiled;
        protected var _infoTitle:GBitmap;
        protected var _playerDes:GTextFiled;
        protected var _playerName:GTextFiled;
        protected var _powDes:GTextFiled;
        protected var _powerTxt:GTextFiled;
        protected var _timeDes:GTextFiled;
        protected var _timeTxt:GTextFiled;
        protected var _posTitle:GBitmap;
        protected var _posAttTile:GBitmap;
        protected var _enterBtn:GLoadedButton;
        protected var _levelName:GTextFiled;
        protected var _orderName:GTextFiled;
        protected var _killTitle:GTextFiled;
        protected var _cdDes:GTextFiled;
        public var leftTime:SecTimerView;
        protected var _powerDes:GBitmap;
        protected var _addPowerTxt:GTextFiled;
        protected var _addS:GTextFiled;
        protected var _bg:GBitmap;
        protected var _rect3d:Rect3DObject;
        protected var _img2d:Img2D;
        private var _bodyPlayer:ActionPlayer;
        private var _wid:int = 672;
        private var _hei:int = 481;
        private var _markX:int = 7;
        private var _markY:int = 34;
        private var _info:Object;
        private var _pos:int;
        private static var _instance:TianDiEnterPanel;

        public function TianDiEnterPanel()
        {
            this.setSize(677, 509);
            title = "" + Language.getString(71948);
            this.layer = LayerManager.windowLayer3D;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap("");
            LoaderManager.instance.load(ImagesConst.TianDiRankChallengBg + ".swf", this.onBgLoadCompl);
            this._killDes = UIFactory.gTextField("" + Language.getString(71949), 83, 437, 150, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2);
            this._tip = UIFactory.gTextField("" + Language.getString(71950), 21, 462, 380, 50, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2);
            this._tip.multiline = true;
            this._tip.wordWrap = true;
            this._posDes = UIFactory.gTextField("" + Language.getString(71951), 428, 92, 100, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._posTxt = UIFactory.gTextField("" + Language.getString(71952), 499, 92, 160, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._killTimesDes = UIFactory.gTextField("" + Language.getString(71953), 428, 113, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._killTimesTxt = UIFactory.gTextField("", 498, 114, 150, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._attrList = UIFactory.getUICompoment(CellsGridSprite);
            this._attrList.colNum = 2;
            this._attrList.vCellWid = 100;
            this._attrList.hCellWid = 25;
            this._attrList.genCellFun = UIFactory.getUICompoment;
            this._attrList.genCells(2, TianDiPosCell);
            this._attrList.x = 452;
            this._attrList.y = 332;
            this.contentTopOf3DSprite.addChild(this._attrList);
            this._killPlayerName = UIFactory.gTextField("", 193, 437, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatLv);
            this._infoTitle = UIFactory.gBitmap(ImagesConst.TianDiRankPosInfoTe, 563, 53, this.contentTopOf3DSprite);
            this._playerDes = UIFactory.gTextField("" + Language.getString(71954), 428, 137, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._playerName = UIFactory.gTextField("", 510, 137, 150, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._powDes = UIFactory.gTextField("" + Language.getString(71955), 428, 159, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2);
            this._powerTxt = UIFactory.gTextField("13246", 511, 158, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._timeDes = UIFactory.gTextField("" + Language.getString(71956), 428, 180, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._timeTxt = UIFactory.gTextField("", 510, 180, 100, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(13));
            this._posTitle = UIFactory.gBitmap(ImagesConst.TianDiRankPosTitle, 562, 220, this.contentTopOf3DSprite);
            this._posAttTile = UIFactory.gBitmap(ImagesConst.TianDiRankPosAttr2, 435, 305, this.contentTopOf3DSprite);
            this._enterBtn = UIFactory.gLoadedButton(ImagesConst.TianDiRankEnterBtn_upSkin, 496, 448, 93, 30, this.contentTopOf3DSprite);
            this._enterBtn.label = "";
            this._levelName = UIFactory.gTextField("", 112, 65, 150, 22, this.contentTopOf3DSprite, GlobalStyle.textFormatChen.setSize(13));
            this._orderName = UIFactory.gTextField("", 272, 65, 150, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatPutong.setSize(13));
            this._killTitle = UIFactory.gTextField("", 438, 260, 200, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatChen.setSize(15).right().setBold(true));
            this._cdDes = UIFactory.gTextField("" + Language.getString(71957), 468, 411, 200, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHong);
            this._powerDes = UIFactory.gBitmap(ImagesConst.TianDiRankPowerDes, 536, 305, this.contentTopOf3DSprite);
            this._addPowerTxt = UIFactory.gTextField("5600", 602, 303, 120, 25, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._addS = UIFactory.gTextField("+", 588, 301, 15, 20, this.contentTopOf3DSprite, GlobalStyle.textFormatHuang2.setSize(15).setBold(true));
            this._cdDes.visible = false;
            this._enterBtn.configEventListener(MouseEvent.CLICK, this.onEnterCopyHd);
            this.leftTime = UIFactory.secTimeView("hh:mm:ss", 516, 428, 100, 100, this.contentTopOf3DSprite);
            this.leftTime.configEventListener(EventName.SecViewTimeChange, this.onTimeChange);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.remove3D();
            this._killDes = null;
            this._tip = null;
            this._posDes = null;
            this._posTxt = null;
            this._killTimesDes = null;
            this._killTimesTxt = null;
            this._attrList = null;
            this._killPlayerName = null;
            this._infoTitle = null;
            this._playerDes = null;
            this._playerName = null;
            this._powDes = null;
            this._powerTxt = null;
            this._timeDes = null;
            this._timeTxt = null;
            this._posTitle = null;
            this._posAttTile = null;
            this._enterBtn = null;
            this._levelName = null;
            this._orderName = null;
            this._killTitle = null;
            this._cdDes = null;
            this._powerDes = null;
            this._addPowerTxt = null;
            this._addS = null;
            this.leftTime.dispose();
            this.leftTime = null;
            this._pos = -1;
            return;
        }// end function

        protected function onBgLoadCompl(param1) : void
        {
            if (isDisposed)
            {
                return;
            }
            this._bg.bitmapData = param1.bitmapData as BitmapData;
            this.init3DRect();
            this.add3dBg();
            this.updateMonster();
            return;
        }// end function

        protected function init3DRect() : void
        {
            this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(this._markX, this._markY, this._wid, this._hei), this);
            Rect3DManager.instance.windowShowHander(null, this);
            return;
        }// end function

        protected function add3dBg() : void
        {
            if (this._rect3d)
            {
                this._rect3d.removeImg(this._img2d);
                this._img2d = new Img2D(null, this._bg.bitmapData, new Rectangle(0, 0, this._wid, this._hei), false);
                this._rect3d.addImg(this._img2d);
            }
            return;
        }// end function

        private function onEnterCopyHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankEnterCopy, {info:this._info, pos:this._pos}));
            return;
        }// end function

        private function onTimeChange(event:DataEvent) : void
        {
            if (this.leftTime == null)
            {
                return;
            }
            if (this.leftTime.secTimerViewData == null)
            {
                this.leftTime.stop();
                return;
            }
            if (this.leftTime.secTimerViewData.leftTime == 0)
            {
                this.setEnterBtn(true);
            }
            return;
        }// end function

        private function setEnterBtn(param1:Boolean) : void
        {
            if (param1)
            {
                var _loc_2:Boolean = false;
                this.leftTime.visible = false;
                this._cdDes.visible = _loc_2;
            }
            else
            {
                var _loc_2:Boolean = true;
                this.leftTime.visible = true;
                this._cdDes.visible = _loc_2;
            }
            return;
        }// end function

        protected function remove3D() : void
        {
            if (this._rect3d)
            {
                if (this._img2d)
                {
                    this._rect3d.removeImg(this._img2d);
                    this._img2d = null;
                }
                if (this._rect3d && this._bodyPlayer)
                {
                    this._rect3d.disposeObj3d(this._bodyPlayer);
                    this._bodyPlayer = null;
                }
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            return;
        }// end function

        public function updateBaseInfo(param1:int) : void
        {
            this._pos = param1;
            this.updateNameAndModule();
            return;
        }// end function

        private function updateNameAndModule() : void
        {
            var _loc_1:* = TianDiRankUtil.getCopyCfgByPos(this._pos);
            var _loc_2:* = _loc_1.jobName;
            var _loc_3:String = "";
            this._killTitle.text = _loc_2 + "";
            this._orderName.text = Language.getStringByParam(71958, TianDiRankUtil.getTypeName(), TianDiRankUtil.getPosNum(this._pos));
            this.updateMonster();
            this.updateAtt(_loc_1.titleId);
            return;
        }// end function

        private function updateMonster() : void
        {
            if (this._rect3d == null || this._pos == -1)
            {
                return;
            }
            var _loc_1:* = TianDiRankUtil.getIndex();
            var _loc_2:* = TianDiRankUtil.getMonsterCodeByPos(_loc_1, this._pos, 1);
            var _loc_3:* = BossConfig.instance.getInfoByCode(_loc_2);
            if (this._rect3d && this._bodyPlayer)
            {
                this._rect3d.disposeObj3d(this._bodyPlayer);
            }
            this._bodyPlayer = FrObjectPool.getObject(ActionPlayer, this);
            this._bodyPlayer.changeAction(ActionName.Stand);
            this._bodyPlayer.hangBoneName = BoneConst.MountHangModelBone;
            this._bodyPlayer.selectEnabled = false;
            this._bodyPlayer.play();
            this._bodyPlayer.setRotation(0, 0, 0);
            this._bodyPlayer.scaleX = 1.5;
            this._bodyPlayer.scaleY = 1.5;
            this._bodyPlayer.scaleZ = 1.5;
            this._bodyPlayer.load(_loc_3.mesh + ".md5mesh", _loc_3.bone + ".skeleton", _loc_3.texture);
            this._rect3d.addObject3d(this._bodyPlayer, 193, 366);
            return;
        }// end function

        public function updateSeverInfo(param1:SPlacardDetailInfo) : void
        {
            if (this._pos == -1)
            {
                return;
            }
            var _loc_2:* = TianDiRankUtil.getIndex();
            var _loc_3:* = param1.bosslevel == 0 ? (1) : (param1.bosslevel);
            var _loc_4:* = TianDiRankUtil.getMonsterCodeByPos(_loc_2, this._pos, _loc_3);
            var _loc_5:* = BossConfig.instance.getInfoByCode(_loc_4);
            var _loc_6:* = _loc_5.name;
            this._levelName.text = Language.getStringByParam(71959, _loc_6);
            this._posTxt.text = _loc_6 + "";
            this._levelName.text = Language.getStringByParam(71960, param1.bosslevel, _loc_6);
            this._killTimesTxt.text = Language.getStringByParam(71961, param1.bosslevel);
            this._killPlayerName.text = "" + param1.failedChallengerName;
            this._playerName.text = param1.defenderInfo.name;
            this._powerTxt.text = "" + param1.defenderInfo.combat;
            if (this._playerName.text == null || this._playerName.text == "")
            {
                this._timeTxt.text = "";
            }
            else
            {
                this._timeTxt.text = "" + TianDiRankUtil.getTime(TianDiRankPassWin.totalTime - param1.defenderInfo.time);
            }
            this._tip.text = Language.getStringByParam(71962, param1.bosslevel, param1.bosslevel);
            this.updateCDTime(0);
            return;
        }// end function

        private function updateAtt(param1:int) : void
        {
            var _loc_4:TianDiPosCell = null;
            var _loc_5:Object = null;
            var _loc_2:* = TianDiRankUtil.getTitleAttr(param1);
            this._attrList.genCells(_loc_2.length, TianDiPosCell);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = this._attrList.cellArr[_loc_3];
                _loc_5 = _loc_2[_loc_3];
                _loc_4.updateInfo(_loc_5["attrName"], _loc_5["attrValue"]);
                _loc_3++;
            }
            this._addPowerTxt.text = "" + TianDiRankUtil.getTitleCombat(param1);
            return;
        }// end function

        public function updateCDTime(param1:int) : void
        {
            if (param1 > 0)
            {
                this.setEnterBtn(false);
                this.leftTime.setLeftTime(param1);
            }
            else
            {
                this.setEnterBtn(true);
                if (this.leftTime)
                {
                    this.leftTime.stop();
                }
            }
            return;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get instance() : TianDiEnterPanel
        {
            if (_instance == null)
            {
                _instance = new TianDiEnterPanel;
            }
            return _instance;
        }// end function

    }
}
